//
//  UIRegProfileViewCtrl.m
//  AccuroFit
//
//  Created by Yongfeng Li on 8/18/15.
//  Copyright (c) 2015 Nci Technology Inc. All rights reserved.
//

#import <AudioToolbox/AudioServices.h>
#import "AppDelegate.h"
#import "UIRegProfileViewCtrl.h"

@interface UIRegProfileViewCtrl ()

@end

@implementation UIRegProfileViewCtrl {
  UILabel* _lblPersonInfoTips;
  
  /*UILabel* _lblLocationTip;
  UIImageView* _ivDropdwon;
  UILabel* _lblDropDownList;
  NIDropDownList* _ddlLocation;
  NSMutableDictionary* _dirLocData;*/
  NSString* _sSelectedLocId;
  NSString* _sSelectedLocNe;
  
  UILabel* _lblGender;
  UISegmentedControl* _scGender;
  UILabel* _lblGenderTip;
    
  UITextField* _txtBodyHgt;
  UILabel* _lblHgtUnit;
  UITextField* _txtHgtInch;
  UILabel* _lblInchUnit;
  //UISegmentedControl* _scHgtUnit;
    
  UITextField* _txtBodyWgt;
  UISegmentedControl* _scWgtUnit;
    
  UILabel* _lblActLevel;
  UISegmentedControl* _scActLevel;
  UITextField* _txtPhoneNum;
    
  UILabel* _lblBirthDay;
  UIDatePicker* _dpBirthDay;
  NSDateFormatter* _dtFmt;
    
  UIButton* _btnProfSubmit;
  UIActivityIndicatorView* _actView;
}

- (void) viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.
  self.view.backgroundColor = [UIColor blackColor];
  CGRect frame = [[UIScreen mainScreen] bounds];
  CGFloat W = frame.size.width;
  CGFloat H = frame.size.height;
  
  [self getSvrStoreInfo];
  [self initViewCtrls:W hgt:H];
  [self createLocationCtrl:W hgt:H];
    
  //AppDelegate *pApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  //_dtFmt = pApp.dtFmt;
  _dtFmt = [[NSDateFormatter alloc]init];
  [_dtFmt setDateFormat:@"MM/dd/yyyy"];

  _sSelectedLocId = @"-1";
  _sSelectedLocNe = @"";
  _actView = nil;
}

- (void) viewWillAppear:(BOOL)animated
{
  self.navigationItem.hidesBackButton = YES;
}

- (void) hideBirthDayDateCol
{
  if(_dpBirthDay != nil) {
    NSInteger nDateIdx = [AppDelegate isLanguageChines]?2:1;
    [_dpBirthDay setDate:[_dtFmt dateFromString:@"1/1/1970"]];
    _dpBirthDay.subviews[0].subviews[0].subviews[nDateIdx].hidden = YES;
    //[_dpBirthDay.subviews[0].subviews[0].subviews[1] setHidden:YES];
  }
  
}

- (void) getSvrStoreInfo
{
  AppDelegate* pApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  if(![pApp isNetWorkConnAvailable])
    return;
  
  /*NSString* sUrl = @"Club/0";
  NSMutableURLRequest *request = [pApp requestWebApiRouter:@"Get" url:sUrl data:nil];
  
  _dirLocData = [[NSMutableDictionary alloc] init];
  // 6.同步发送请求
  //[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
  NSData *data= [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  if (data != nil) {
    NSError *e = nil;
    NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &e];
    for(NSDictionary *item in jsonArray) {
      //NSLog(@"Item: %@", item);
      NSString* sKey = [item objectForKey:@"_nLocaId"];
      NSString* sName = [item objectForKey: @"_sStoreName"];
      NSString* sAddr = [item objectForKey:@"_sStoreAddr"];
      [_dirLocData setValue: [NSString stringWithFormat:@"%@(%@)", sName, sAddr] forKey:sKey];
    }
  }*/
  return;
}

- (void) createLocationCtrl:(CGFloat) W hgt:(CGFloat)H {
  //AppDelegate* pApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  //BOOL bChn = [AppDelegate isLanguageChines];
  
  //BOOL bIpad = H > 1000;
  //BOOL bWider = W > 320;
  
  /*CGFloat xPos = bIpad? 230: bWider? 100: 90;
  CGFloat yPos = bWider? 120: 94;
  //CGFloat fCtrlWid =  bChn?120: 80;
  //CGFloat fDelta = bWider? 40: 35;
  
  //location
  UIImage* iDorpDown = [UIImage imageNamed:@"ic-dropdown.png"];
  _ivDropdwon = [[UIImageView alloc] initWithFrame:CGRectMake(xPos-20, yPos, W-(bIpad?xPos*3/2:xPos)+10, 30)];
  _ivDropdwon.image = iDorpDown;
  [self.view addSubview:_ivDropdwon];
  UITapGestureRecognizer *ivSingleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTapDropDown)];
  ivSingleTap.numberOfTapsRequired = 1;
  [_ivDropdwon setUserInteractionEnabled:YES];
  [_ivDropdwon addGestureRecognizer:ivSingleTap];
  
  _lblDropDownList = [[UILabel alloc] initWithFrame:CGRectMake(xPos-10, yPos, W-xPos-20, 25)];
  _lblDropDownList.textColor = [UIColor grayColor];
  _lblDropDownList.font = [UIFont systemFontOfSize: 16.0];
  _lblDropDownList.backgroundColor = [UIColor clearColor];
  _lblDropDownList.textAlignment = NSTextAlignmentLeft;
  _lblDropDownList.text = @"tap to choose location...";
  [self.view addSubview:_lblDropDownList];
  
  
  _ddlLocation = [[NIDropDownList alloc] initWithFrame:CGRectMake(bIpad?xPos-10: 20, yPos+25, W-(bIpad?xPos:0)-30, W-160) type:99];
  _ddlLocation.delegate = self;
  [self.view addSubview:_ddlLocation];
  //location data
  
  [_ddlLocation setListData:_dirLocData curSel:@"0"];*/
}

- (void) initViewCtrls:(CGFloat) W hgt:(CGFloat)H {
    AppDelegate* pApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    BOOL bChn = [AppDelegate isLanguageChines];
    
    BOOL bIpad = H > 1000;
    BOOL bWider = W > 320;
    CGFloat xPos = bIpad? 120: bWider? 40: 30;
    CGFloat yPos = bWider? 85: 65;
    CGFloat fCtrlWid =  bChn?120: 80;
    CGFloat fDelta = bWider? 40: 35;
    
    //CGFloat fWid = W - xPos * 2;
    //CGFloat fHgt = bIpad? 36: (bWider?32:24);
    
    
    _lblPersonInfoTips = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, W-2*xPos, 30)];
    _lblPersonInfoTips.font = [UIFont systemFontOfSize: bIpad? 24.0: (bWider?18: 14.0)];
    _lblPersonInfoTips.textColor = [UIColor whiteColor];
    _lblPersonInfoTips.textAlignment = NSTextAlignmentLeft;
    _lblPersonInfoTips.text = NSLocalizedString(@"Personal Information", nil);
    [self.view addSubview:_lblPersonInfoTips];
    
    if(H > 480) {
      yPos += fDelta;
      
      /*_lblLocationTip = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos-5, W-2*xPos, 30)];
      _lblLocationTip.font = [UIFont systemFontOfSize: bIpad? 22.0: (bWider?16: 14.0)];
      _lblLocationTip.textColor = [UIColor grayColor];
      _lblGender.textAlignment = NSTextAlignmentLeft;
      _lblLocationTip.text = @"Store:";
      [self.view addSubview:_lblLocationTip];*/
      
      yPos += 30;
      _lblGender = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, W-2*xPos, 30)];
      _lblGender.font = [UIFont systemFontOfSize: bIpad? 22.0: (bWider?16: 14.0)];
      _lblGender.textColor = [UIColor grayColor];
      _lblGender.textAlignment = NSTextAlignmentLeft;
      _lblGender.text = @"Gender:";
      [self.view addSubview:_lblGender];
    }
  
    //yPos += fDelta / (bWider?1.2: 1);
  xPos += 90;
  yPos += fDelta /  (bWider?3.2: 3);
  _scGender = [[UISegmentedControl alloc] initWithItems:@[@"Woman", @"Man"]];
  _scGender.frame = CGRectMake(xPos, yPos, 120, 28);
  _scGender.tintColor = [UIColor lightGrayColor];
  UIImage* iSex = [pApp getImageScale:@"ic_female.png" scale:1.0];
  [_scGender setImage:iSex forSegmentAtIndex:0];
  iSex = [pApp getImageScale:@"ic_male.png" scale:1.0];
  [_scGender setImage:iSex forSegmentAtIndex:1];
  [_scGender addTarget:self action:@selector(onTapFieldChg:) forControlEvents:UIControlEventValueChanged];
  _scGender.selectedSegmentIndex = 1;
  [self.view addSubview:_scGender];
    
    _lblGenderTip = [[UILabel alloc] initWithFrame:CGRectMake(xPos+125, yPos, fCtrlWid * 2, 30)];
    _lblGenderTip.font = [UIFont systemFontOfSize: bIpad? 22.0: (bWider?16: 14.0)];
    _lblGenderTip.textColor = [UIColor whiteColor];
    _lblGenderTip.textAlignment = NSTextAlignmentLeft;
    _lblGenderTip.text = @": Male";
    [self.view addSubview:_lblGenderTip];
  
  //body wgt
  yPos += fDelta;
  xPos = bIpad? 120: bWider? 40: 30;
  _txtBodyWgt = [[UITextField alloc] initWithFrame:CGRectMake(xPos, yPos,fCtrlWid, 28)];
  _txtBodyWgt.textColor = [UIColor blackColor];
  _txtBodyWgt.backgroundColor = [UIColor whiteColor];
  _txtBodyWgt.font = [UIFont systemFontOfSize:(W>500)?17:14];
  _txtBodyWgt.borderStyle = UITextBorderStyleRoundedRect;
  _txtBodyWgt.placeholder = @"";//NSLocalizedString(@"Weight", nil);//@"Weight";
  _txtBodyWgt.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  _txtBodyWgt.textAlignment = NSTextAlignmentRight;
  [self.view addSubview:_txtBodyWgt];
  
  xPos +=  fCtrlWid + 10;
  _scWgtUnit = [[UISegmentedControl alloc] initWithFrame:CGRectMake(xPos, yPos, fCtrlWid* 1.5, 28)];
  _scWgtUnit.tintColor = [UIColor lightGrayColor];
  [_scWgtUnit insertSegmentWithTitle:@"kg" atIndex:0 animated:NO];
  [_scWgtUnit insertSegmentWithTitle:@"kg" atIndex:1 animated:NO];
  _scWgtUnit.selectedSegmentIndex = bChn? 0: 1;
  [_scWgtUnit addTarget:self action:@selector(wgtUnitChged:) forControlEvents:UIControlEventValueChanged];
  [self.view addSubview:_scWgtUnit];
  
  yPos += fDelta;
  xPos = bIpad? 120: bWider? 40: 30;
  _txtBodyHgt = [[UITextField alloc] initWithFrame:CGRectMake(xPos, yPos, fCtrlWid, 28)];
  _txtBodyHgt.textColor = [UIColor blackColor];
  _txtBodyHgt.backgroundColor = [UIColor whiteColor];
  _txtBodyHgt.font = [UIFont systemFontOfSize:bIpad?18:14];
  _txtBodyHgt.borderStyle = UITextBorderStyleRoundedRect;
  _txtBodyHgt.placeholder = @"";//NSLocalizedString(@"Height", nil);//@"Height";
  _txtBodyHgt.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  _txtBodyHgt.textAlignment = NSTextAlignmentRight;
  [self.view addSubview:_txtBodyHgt];
    
  //hgt unit
  xPos += fCtrlWid + 5; //W/2+fHgtWid+8
  _lblHgtUnit = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, fCtrlWid/3+10, 25)];
  _lblHgtUnit.textColor = [UIColor whiteColor];
  _lblHgtUnit.backgroundColor = [UIColor clearColor];
  _lblHgtUnit.text =  bChn?@"cm":@"ft"; //@"M/D/yyyy";
  _lblHgtUnit.textAlignment = NSTextAlignmentLeft;
  _lblHgtUnit.font = [UIFont systemFontOfSize:bIpad?20:16];
  [self.view addSubview:_lblHgtUnit];
    
  //hgt inch
  xPos +=  fCtrlWid/3 + 2;//(W > 500)? (W/2 + 100): (W/2 + 70);
  _txtHgtInch = [[UITextField alloc] initWithFrame:CGRectMake(xPos+10, yPos, fCtrlWid, 28)];
  _txtHgtInch.textColor = [UIColor blackColor];
  _txtHgtInch.backgroundColor = [UIColor whiteColor];
  _txtHgtInch.font = [UIFont systemFontOfSize:bIpad?20:16];
  _txtHgtInch.borderStyle = UITextBorderStyleRoundedRect;
  _txtHgtInch.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
  _txtHgtInch.textAlignment = NSTextAlignmentRight;
  _txtHgtInch.placeholder = @"";//NSLocalizedString(@"Inch", nil);
  [self.view addSubview:_txtHgtInch];
  _txtHgtInch.hidden = bChn;
    
  xPos +=  fCtrlWid + 15;
  _lblInchUnit = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, fCtrlWid, 25)];
  _lblInchUnit.textColor = [UIColor whiteColor];
  _lblInchUnit.backgroundColor = [UIColor clearColor];
  _lblInchUnit.text =  @"inch"; //@"M/D/yyyy";
  _lblInchUnit.textAlignment = NSTextAlignmentLeft;
  _lblInchUnit.font = [UIFont systemFontOfSize:bIpad?20:16];
  [self.view addSubview:_lblInchUnit];
  _lblInchUnit.hidden = bChn;
  
    
  //exec level
  yPos += fDelta;
  xPos = bIpad? 120: bWider? 40: 30;

  _lblActLevel = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, W-2*xPos, 30)];
  _lblActLevel.font = [UIFont systemFontOfSize: bIpad? 22.0: (bWider?16: 14.0)];
  _lblActLevel.textColor = [UIColor grayColor];
  _lblActLevel.textAlignment = NSTextAlignmentLeft;
  _lblActLevel.text = @"Active level";
  [self.view addSubview:_lblActLevel];
  
  yPos += fDelta / 1.2;
  _scActLevel = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"Ordinary", nil), NSLocalizedString(@"Amateur", nil), NSLocalizedString(@"Professional", nil)]];
  /*_scActLevel = [[UISegmentedControl alloc] initWithItems:@[NSLocalizedString(@"Ordinary", nil),
                                                        NSLocalizedString(@"Amateur", nil), NSLocalizedString(@"Professional", nil)]];*/
  _scActLevel.frame = CGRectMake(xPos, yPos, W-2*xPos, 28);
  _scActLevel.tintColor = [UIColor lightGrayColor];
  _scActLevel.selectedSegmentIndex = 0;
  UIFont *Boldfont = [UIFont boldSystemFontOfSize:13.0f];
  NSDictionary *attributes = [NSDictionary dictionaryWithObject:Boldfont forKey:NSFontAttributeName];
  [_scActLevel setTitleTextAttributes:attributes forState:UIControlStateNormal];
  [_scActLevel addTarget:self action:@selector(onTapFieldChg:) forControlEvents:UIControlEventValueChanged];
  [self.view addSubview:_scActLevel];


  //birth date
  yPos += fDelta;
  _lblBirthDay = [[UILabel alloc] initWithFrame:CGRectMake(xPos, yPos, W-2*xPos, 30)];
  _lblBirthDay.font = [UIFont systemFontOfSize: bIpad? 22.0: (bWider?16: 14.0)];
  _lblBirthDay.textColor = [UIColor grayColor];
  _lblBirthDay.textAlignment = NSTextAlignmentLeft;
  _lblBirthDay.text = @"Date of Birth";
  [self.view addSubview:_lblBirthDay];
    
  yPos += fDelta / 1.2;
  //_dpBirthDay = [[UIDatePicker alloc] initWithFrame:CGRectMake(bIpad?xPos:10, yPos, W-2*(bIpad?xPos:10), 200)];
  _dpBirthDay = [[UIDatePicker alloc] initWithFrame:CGRectMake(xPos/(bIpad?1:20), yPos, W- xPos * 2/(bIpad?1:20), 200)];
  _dpBirthDay.backgroundColor = [UIColor whiteColor];
  //_dpBorn.font = [UIFont systemFontOfSize:12];
  _dpBirthDay.datePickerMode = UIDatePickerModeDate;
  
  /*_dpBirthDay.minimumDate = [[NSDate date] dateByAddingTimeInterval:-_OneDaySeconds * 365 * 100];
  _dpBirthDay.maximumDate = [NSDate date];
  [_dpBirthDay setDate:[[NSDate date]dateByAddingTimeInterval:-_OneDaySeconds * 365 * 30]];*/
  
  _dpBirthDay.minimumDate = [[NSDate date] dateByAddingTimeInterval:-60*60*24*365*100];
  _dpBirthDay.maximumDate = [NSDate date];
  [_dpBirthDay setDate:[[NSDate date]dateByAddingTimeInterval:-60*60*24*365*30]];
  
  //_dpBirthDay.borderStyle = UITextBorderStyleRoundedRect;
  //_dpBorn.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
  [_dpBirthDay setHidden:NO];
  //_dpBorn.dataSource = self;
  //_dpBorn.delegate = self;
  //[_dpBorn.delegate addTarget:self action:@selector(datePickerValChged:) forControlEvents:UIControlEventValueChanged];
    
  _dpBirthDay.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
  [_dpBirthDay addTarget:self action:@selector(onTapFieldChg:) forControlEvents:UIControlEventValueChanged];
  [self.view addSubview:_dpBirthDay];
   //_dpBirthDay.subviews[0].subviews[0].subviews[1].hidden = YES;
    
   
   
  if(bIpad) {
    yPos += 220;
  }
  else {
    xPos =  W - (bIpad?150: bWider? 140: 130);
    yPos = bWider? 80: 65;
  }
  _btnProfSubmit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
  _btnProfSubmit.frame = CGRectMake(xPos, yPos, 120, 26);
  [_btnProfSubmit setBackgroundImage:[UIImage imageNamed:@"btn-submit.png"] forState:UIControlStateNormal];
  [_btnProfSubmit addTarget:self action:@selector(onProfileSubmit:) forControlEvents:UIControlEventTouchUpInside];
  [self.view addSubview:_btnProfSubmit];
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
  _lblPersonInfoTips.text = NSLocalizedString(@"No enough memory!", nil);
  AudioServicesPlaySystemSound(1112);
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (NSString *) niDropDownDelegateMethod: (NIDropDownList *) sender
{
  _sSelectedLocId = sender.sSelValId;
  _sSelectedLocNe = sender.sSelText;
  //_lblDropDownList.text = _sSelectedLocNe;
  //[_ddlLocation hideDropDownList];
  return _sSelectedLocId;
}

- (void) onTapDropDown
{
  /*if(_ddlLocation.isPopup) {
     [_ddlLocation hideDropDownList];
  }
  else {
    [_ddlLocation popupDropDownList];
  }*/
}

- (void) wgtUnitChged:(id)sender
{
    BOOL bLb = _scWgtUnit.selectedSegmentIndex == 1;
    _lblHgtUnit.text =  bLb?@"ft":@"cm";
    _lblInchUnit.hidden = !bLb;
    _txtHgtInch.hidden = !bLb;
    _lblPersonInfoTips.text = @"Wgt unit chged";
}

- (void) onTapFieldChg:(id)sender
{
    if(sender == _scGender) {
        _lblGenderTip.text = (_scGender.selectedSegmentIndex == 0)? @": Female":@": Male";
    }
    else {
        if([_txtBodyHgt isFirstResponder])
        [_txtBodyHgt resignFirstResponder];
        else if([_txtHgtInch isFirstResponder])
            [_txtHgtInch resignFirstResponder];
        else if([_txtBodyWgt isFirstResponder])
            [_txtBodyWgt resignFirstResponder];
    }
    return;
}

- (void) onProfileSubmit:(id)sender
{
    //_lblPersonInfoTips.text = @"Submit profile";
    [self updUserProfInfoOnSvr];
}

- (void) updUserProfInfoOnSvr
{
  AppDelegate* pApp = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  LoginBodyInfo * bodyInfo = pApp.m_bodyInfo;
  NSInteger nBodyId = bodyInfo.m_nBodyId;
  /*if(nBodyId < 1) {
    _lblPersonInfoTips.text = @"Body ID? Please Login.";
    AudioServicesPlaySystemSound(1109);
    return;
  }*/
    
  if(_actView == nil) {
    CGRect rt = _btnProfSubmit.frame;
    rt.origin.x += rt.size.width - rt.size.height * 2;
    rt.size.width = rt.size.height;
    _actView = [[UIActivityIndicatorView alloc] initWithFrame:rt];
    _actView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
    _actView.hidesWhenStopped = YES;
    [self.view addSubview:_actView];
  }
    _btnProfSubmit.hidden = YES;
    [_actView startAnimating];
    
  //create User info JSON data
  /*int nLocId = _sSelectedLocId.intValue;
  if(nLocId <= 0) {
    [_actView stopAnimating];
    _btnProfSubmit.hidden = NO;
    _lblPersonInfoTips.text = @"Please Select Club Location!";
    AudioServicesPlaySystemSound(1112);
    return;
  }*/
  //_lblPersonInfoTips.text = [NSString stringWithFormat:@"%d", nLocId];
  //return;
  
  short nGender = _scGender.selectedSegmentIndex;
  NSDate* dtBorn = _dpBirthDay.date;
  
  NSInteger nUnit = _scWgtUnit.selectedSegmentIndex;
  NSString* sUnit = [NSString stringWithFormat:@"%ld", (long)(nUnit+1)];
  NSString* sWgt = _txtBodyWgt.text;
  float fHgt = 0.0;
  if (nUnit == 1)
    fHgt = _txtBodyHgt.text.intValue + (_txtHgtInch.text.intValue / 12.0);
  else
    fHgt = _txtBodyHgt.text.intValue / 100.0;
  short nActLvl = _scActLevel.selectedSegmentIndex;
    
  NSDictionary *regInfo = @{
                            @"BodyId" : [NSString stringWithFormat:@"%ld", (long)nBodyId],
                            @"LocationId" : _sSelectedLocId,
                            @"Gender" : [NSString stringWithFormat:@"%d", nGender],
                            @"BodyHgt" : [NSString stringWithFormat:@"%.3f", fHgt],
                            @"BodyWgt" : sWgt,
                            @"WgtUnit" : sUnit,
                            @"HgtUnit" : sUnit,
                            @"BodyBirthDay" :  [_dtFmt stringFromDate: dtBorn],
                            @"FitLvl" : [NSString stringWithFormat:@"%d",nActLvl],
                            @"ChestSize" : @"0",
                            @"WaistLine" :  @"0"
                            };
    NSMutableURLRequest *request = [pApp requestWebApiRouter:@"POST" url:@"Mob" data:regInfo];
    
    
    // 6.发送请求
    //NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
      if (data == nil || connectionError)
        return;
        
      [_actView stopAnimating];
      _btnProfSubmit.hidden = NO;
      NSString* sRecv = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
      sRecv = [sRecv substringFromIndex:1];
      if([sRecv hasPrefix:@"Failed"]) {
        _lblPersonInfoTips.text = sRecv;
        AudioServicesPlaySystemSound(1109);
        return;
      }
      NSString* sTagId = [sRecv substringWithRange: NSMakeRange(0, sRecv.length-1)];
      Byte nUnit = _scWgtUnit.selectedSegmentIndex + 1;
      
      [pApp storeRegBodyInfo:nBodyId tag:sTagId gerder:(Byte)nGender born:dtBorn wgt:sWgt.floatValue wun:nUnit
                         hgt:fHgt hun:nUnit lvl:(Byte)nActLvl email:nil first:nil last:nil store:_sSelectedLocNe];
      [pApp enterMainPage];

    }];
}

@end
